import Vue from 'vue'
import VueRouter from 'vue-router'
import layout from '@/views/Index'
import FlyrayRouter from './flyray-router'
import Store from '../store/'
import Wel from '@/views/Wel'
import Setting from '@/views/setting/Index'
import message from '@/views/setting/message'
import password from '@/views/setting/password'
import safe from '@/views/setting/safe'
import globaStyle from '@/views/setting/globaStyle'
import Analysis from '@/views/dashboard//Analysis'

Vue.use(VueRouter)

const Router = new VueRouter({
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.body.scrollTop
      }
      return {
        x: 0,
        y: to.meta.savedPosition || 0
      }
    }
  },
  routes: [
    {
      path: '/',
      name: 'index',
      redirect: 'analysis',
    },
    {
      path: '/wel',
      component: layout,
      redirect: '/wel/index',
      children: [{
        path: 'index',
        component: Wel
      }]
    },
    {
      path: '/setting',
      component: layout,
      redirect: '/setting/message',
      children: [{
        path: 'index',
        component: Setting,
        children: [
          {
            path: '/setting/message',
            component: message
          },
          {
            path: '/setting/password',
            component: password
          },
          {
            path: '/setting/safe',
            component: safe
          },
          {
            path: '/setting/globaStyle',
            component: globaStyle
          },

        ]
      }]
    },
    {
      path: '/analysis',
      component: layout,
      redirect: '/analysis/index',
      children: [{
        path: 'index',
        component: Analysis
      }]
    },
    {
      path: '/login',
      name: '登录页',
      component: () =>
        import(/* webpackChunkName: "page" */ '@/views/login/index'),
      meta: {
        keepAlive: true,
        isTab: false,
        isAuth: false
      }
    },
    ,
    {
      path: '/lock',
      name: '锁屏页',
      component: () =>
        import(/* webpackChunkName: "page" */ '@/views/setting/lock/index'),
      meta: {
        keepAlive: true,
        isTab: false,
        isAuth: false
      }
    },
    {
      path: '*',
      redirect: '/404'
    },
    {
      path: '/404',
      component: () =>
        import(/* webpackChunkName: "page" */ '@/components/error-page/404'),
      name: '404',
      meta: {
        keepAlive: true,
        isTab: false,
        isAuth: false
      }

    }
  ]
})

FlyrayRouter.install(Router, Store)
Router.$flyrayRouter.formatRoutes(Store.state.user.menu, true)

export default Router
